<?php
namespace app\admin\controller;
// use think\Db;
// use think\captcha\Captcha;
class Adminuser extends Come{
    public function adminuser(){
        $res=db('administrator_role')->select();
        $this->assign('res',$res);
        return $this->fetch('admin-user');
    }

    public function user(){
        if(isset($_POST['up'])){
            $name=input('param.name','','htmlspecialchars');
            $tell=input('param.tell','','htmlspecialchars');
            $email=input('param.email','','htmlspecialchars');
            $pwd=input('param.pwd','','htmlspecialchars');
            $role_id=input('param.id_num','','htmlspecialchars');

            $file=request()->file('image');
            if($file){
                $info = $file->validate(['size'=>4*1024*1024,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'uploads');
                if($info){
                    $path=$info->getSaveName();
                    $img_src="/uploads/".$path;
                }else{
                    //	上传失败获取错误信息
                    $this->error($file->getError());
                }
            }else{
                $this->error("必须上传图片");
            }$data=[
                'name'=>$name,
                'tell'=>$tell,
                'avatar'=>$img_src,
                'email'=>$email,
                'pwd'=>md5($pwd),
                'role_id'=>$role_id,
                
            ];
            $checkTell=db('admin_user')->where("tell='{$tell}'")->find();
            if($tell==$checkTell['tell']){
                $this->error('手机号码已存在');
            }

            $ret=db('admin_user')->insertGetId($data);
            if($ret>0){
                $this->success('添加成功!','admin/adminuser/adminuser');
            }else{
                $this->error('添加失败');
            }
            
        }
        
    }
    
}